package com.oocl.sc.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.oocl.sc.dao.SmenuDao;
import com.oocl.sc.entity.Smenu;
import com.oocl.sc.util.DbUtil;

public class SmenuDaoImpl implements SmenuDao {

	public List<Smenu> loadAllMenu() {
		List<Smenu> smenus = new ArrayList<>();
		Smenu smenu = null;
		String sql = "select * from smenu";
		Connection conn = null;
		PreparedStatement st = null;
		ResultSet rs = null;

		try {
			conn = DbUtil.getConnection();
			st = conn.prepareStatement(sql);
			rs = st.executeQuery();
			while (rs.next()) {
				smenu = new Smenu();
				smenu.setMid(rs.getInt("mid"));
				smenu.setName(rs.getString("name"));
				smenu.setPrice(rs.getInt("price"));
				smenu.setIcon(rs.getString("icon"));
				smenus.add(smenu);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DbUtil.free(conn, st, rs);
		}

		return smenus;

	}

}
